package cs.ui250.carnatic;

public class Raga {

	private int ID;
	private String name;
	private int S = 0, R1 = 0, R2 = 0, R3 = 0, G1 = 0, G2 = 0, G3 = 0, M1 = 0,
			M2 = 0, P = 0, D1 = 0, D2 = 0, D3 = 0, N1 = 0, N2 = 0, N3 = 0;
	private String[] swaras;
	private Song[] songArray;
	private String songString;

	// Constructor 1
	Raga(int ID, String name, int S1, int S2, int S3, int S4, int S5, int S6,
			int S7) {
		this.ID = ID;
		this.name = name;
		this.songString = "";

		String[] swaras = new String[7];
		switch (S1) {
		case 0:
			S = 1;
			swaras[0] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[0] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[0] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[0] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[0] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[0] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[0] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[0] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[0] = "M2";
			break;
		case 9:
			P = 1;
			swaras[0] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[0] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[0] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[0] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[0] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[0] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[0] = "N3";
			break;
		default:
			break;
		}

		switch (S2) {
		case 0:
			S = 1;
			swaras[1] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[1] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[1] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[1] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[1] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[1] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[1] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[1] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[1] = "M2";
			break;
		case 9:
			P = 1;
			swaras[1] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[1] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[1] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[1] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[1] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[1] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[1] = "N3";
			break;
		default:
			break;
		}

		switch (S3) {
		case 0:
			S = 1;
			swaras[2] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[2] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[2] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[2] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[2] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[2] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[2] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[2] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[2] = "M2";
			break;
		case 9:
			P = 1;
			swaras[2] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[2] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[2] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[2] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[2] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[2] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[2] = "N3";
			break;
		default:
			break;
		}

		switch (S4) {
		case 0:
			S = 1;
			swaras[3] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[3] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[3] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[3] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[3] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[3] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[3] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[3] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[3] = "M2";
			break;
		case 9:
			P = 1;
			swaras[3] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[3] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[3] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[3] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[3] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[3] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[3] = "N3";
			break;
		default:
			break;
		}

		switch (S5) {
		case 0:
			S = 1;
			swaras[4] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[4] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[4] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[4] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[4] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[4] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[4] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[4] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[4] = "M2";
			break;
		case 9:
			P = 1;
			swaras[4] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[4] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[4] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[4] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[4] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[4] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[4] = "N3";
			break;
		default:
			break;
		}

		switch (S6) {
		case 0:
			S = 1;
			swaras[5] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[5] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[5] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[5] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[5] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[5] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[5] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[5] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[5] = "M2";
			break;
		case 9:
			P = 1;
			swaras[5] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[5] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[5] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[5] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[5] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[5] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[5] = "N3";
			break;
		default:
			break;
		}

		switch (S7) {
		case 0:
			S = 1;
			swaras[6] = "S";
			break;
		case 1:
			R1 = 1;
			swaras[6] = "R1";
			break;
		case 2:
			R2 = 1;
			swaras[6] = "R2";
			break;
		case 3:
			R3 = 1;
			swaras[6] = "R3";
			break;
		case 4:
			G1 = 1;
			swaras[6] = "G1";
			break;
		case 5:
			G2 = 1;
			swaras[6] = "G2";
			break;
		case 6:
			G3 = 1;
			swaras[6] = "G3";
			break;
		case 7:
			M1 = 1;
			swaras[6] = "M1";
			break;
		case 8:
			M2 = 1;
			swaras[6] = "M2";
			break;
		case 9:
			P = 1;
			swaras[6] = "P";
			break;
		case 10:
			D1 = 1;
			swaras[6] = "D1";
			break;
		case 11:
			D2 = 1;
			swaras[6] = "D2";
			break;
		case 12:
			D3 = 1;
			swaras[6] = "D3";
			break;
		case 13:
			N1 = 1;
			swaras[6] = "N1";
			break;
		case 14:
			N2 = 1;
			swaras[6] = "N2";
			break;
		case 15:
			N3 = 1;
			swaras[6] = "N3";
			break;
		default:
			break;
		}

	}

	// Constructor 2
	Raga(int ID, String name, int S, int R1, int R2, int R3, int G1, int G2,
			int G3, int M1, int M2, int P, int D1, int D2, int D3, int N1,
			int N2, int N3, String songs) {

		this.ID = ID;
		this.name = name;
		this.songString = songs;
		int count = 0;
		swaras = new String[7];
		if (S == 1) {
			S = 1;
			swaras[count] = "S";
			count++;
		}
		if (R1 == 1) {
			R1 = 1;
			swaras[count] = "R1";
			count++;
		}
		if (R2 == 1) {
			R2 = 1;
			swaras[count] = "R2";
			count++;
		}
		if (R3 == 1) {
			R3 = 1;
			swaras[count] = "R3";
			count++;
		}
		if (G1 == 1) {
			G1 = 1;
			swaras[count] = "G1";
			count++;
		}
		if (G2 == 1) {
			G2 = 1;
			swaras[count] = "G2";
			count++;
		}
		if (G3 == 1) {
			G3 = 1;
			swaras[count] = "G3";
			count++;
		}
		if (M1 == 1) {
			M1 = 1;
			swaras[count] = "M1";
			count++;
		}
		if (M2 == 1) {
			M2 = 1;
			swaras[count] = "M2";
			count++;
		}
		if (P == 1) {
			P = 1;
			swaras[count] = "P";
			count++;
		}
		if (D1 == 1) {
			D1 = 1;
			swaras[count] = "D1";
			count++;
		}
		if (D2 == 1) {
			D2 = 1;
			swaras[count] = "D2";
			count++;
		}
		if (D3 == 1) {
			D3 = 1;
			swaras[count] = "D3";
			count++;
		}
		if (N1 == 1) {
			N1 = 1;
			swaras[count] = "N1";
			count++;
		}
		if (N2 == 1) {
			N2 = 1;
			swaras[count] = "N2";
			count++;
		}
		if (N3 == 1) {
			N3 = 1;
			swaras[count] = "N3";
			count++;
		}
		parseSongString();
	}// CONSTRUCTOR 2

	/**
	 * Adds new Song object to the Raga's collection of songs
	 * 
	 * @param song
	 */
	public void addSongs(String songs) {
		this.songString += songs;
	}

	/**
	 * Prints list of swaras contained in Raga in ascending scale
	 * 
	 * @return String of swaras
	 */
	public String printArohana() {
		String Arohana = "";
		for (int i = 0; i <= swaras.length - 1; i++) {
			Arohana += swaras[i] + " ";
		}

		return Arohana;
	}

	/**
	 * Prints list of swaras contained in Raga in descending scale
	 * 
	 * @return String of swaras
	 */
	public String printAvarohana() {
		String Avarohana = "";
		for (int i = swaras.length - 1; i >= 0; i--) {
			Avarohana += swaras[i] + " ";
		}

		return Avarohana;
	}

	public int getID() {
		return ID;
	}

	public String getName() {
		return name;
	}

	public String getSongString() {
		return songString;
	}

	public Song[] getSongArray() {
		return songArray;
	}

	public int getS() {
		return S;
	}

	public int getR1() {
		return R1;
	}

	public int getR2() {
		return R2;
	}

	public int getR3() {
		return R3;
	}

	public int getG1() {
		return G1;
	}

	public int getG2() {
		return G2;
	}

	public int getG3() {
		return G3;
	}

	public int getM1() {
		return M1;
	}

	public int getM2() {
		return M2;
	}

	public int getP() {
		return P;
	}

	public int getD1() {
		return D1;
	}

	public int getD2() {
		return D2;
	}

	public int getD3() {
		return D3;
	}

	public int getN1() {
		return N1;
	}

	public int getN2() {
		return N2;
	}

	public int getN3() {
		return N3;
	}

	private void parseSongString() {
		String[] toParse = songString.split("\\|");
		if (toParse[0].length() == 0) {
			songArray = null;
			return;
		}
		songArray = new Song[toParse.length];
		for (int i = 0; i < songArray.length; i++) {
			songArray[i] = new Song(toParse[i]);
		}
	}
}
